// pages/organization/admin/join_list.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    org_id: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "申请列表"
    })
    // console.log(options);
    this.setData({
      org_id: options.org_id,
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.join_list_request();
    // console.log(this.data.join_list);

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //获取申请列表
  join_list_request: function () {
    var org_id = this.data.org_id;
    var yuyue_session = wx.getStorageSync("yuyue_session");
    var that = this;
    var list = [];
    // console.log(org_id);
    wx.request({
      url: app.globalData.default_url,
      data: {
        action: "api.v1.organization.receive_list",
        org_id: org_id,
        // yuyue_session: yuyue_session,
      },
      success: function (res) {
        console.log(res);

        list = res.data.data;
        var join_list = [];

        for (var item in list) {

          if (list[item].type == "0") {

            join_list.push(list[item]);
          }
          console.log(list[item]);
        }

        that.setData({
          join_list: join_list
        })
      }
    })

  },
  audit_request: function (e) {
    console.log(e);
    var yuyue_session = e.currentTarget.dataset.join_session;
    var audit = e.currentTarget.dataset.audit;
    var org_id = this.data.org_id;
    var that = this;
    wx.request({
      url: app.globalData.default_url,
      data: {
        action: "api.v1.organization.audit",
        org_id: org_id,
        audit: audit,
        yuyue_session: yuyue_session
      }
      , success: function (res) {
        if (res.data) {
          wx.showToast({
            title: '操作成功',
          })
          that.onShow();
        }
        console.log(res);

      }, fail: function (res) {
        console.log(res);
      }
    })
  }

})